﻿package org.xhs.report.common.model
{
    import baidu.lib.serialization.*;
    import baidu.wenku.common.*;
    import flash.events.*;
    import flash.external.*;

    public class StoreModel extends EventDispatcher
    {
        protected var _isStore:Boolean = false;
        protected var _isFree:Boolean = true;
        protected var _hasRecom:Boolean = true;
        protected var _storeFreePages:int = 1;
        protected var _storePrice:Number = 18;
        protected var _storeDiscount:Number = 40;
        protected var _storeCookie:String = "";
        protected var _storeCallBack:String = "";
        protected var _recomData:Array;

        public function StoreModel(param1:IEventDispatcher = null)
        {
            super(param1);
            this.init();
            return;
        }// end function

        protected function init() : void
        {
            var _loc_1:Object = null;
            if (ExternalInterface.available)
            {
                try
                {
                    _loc_1 = ExternalInterface.call(JSInterface.AS_STORE);
                }
                catch (e:Error)
                {
                }
            }
            if (_loc_1 && _loc_1.ispay)
            {
                this._isStore = Boolean(_loc_1.ispay);
                this._isFree = _loc_1.ispay == 1;
                this._storeFreePages = int(_loc_1.content.proportion ? (_loc_1.content.proportion) : (this._storeFreePages));
                this._storeFreePages = _loc_1.ispay == 2 ? (this._storeFreePages) : (-1);
                this._storePrice = Number(_loc_1.content.wenku_price ? (_loc_1.content.wenku_price) : (this._storePrice));
                this._storeDiscount = Number(_loc_1.content.discount ? (_loc_1.content.discount) : (this._storeDiscount));
                this._storeCookie = String(_loc_1.content.cookie ? (_loc_1.content.cookie) : (this._storeCookie));
                this._storeCallBack = String(_loc_1.content.callback ? (_loc_1.content.callback) : (this._storeCallBack));
            }
            if (this._isFree)
            {
                this.initRecom();
            }
            return;
        }// end function

        protected function initRecom() : void
        {
            var _loc_1:Array = null;
            this._hasRecom = false;
            if (ExternalInterface.available)
            {
                try
                {
                    _loc_1 = JSON.decode(ExternalInterface.call(JSInterface.AS_RECOM));
                }
                catch (e:Error)
                {
                }
            }
            if (_loc_1 && _loc_1.length)
            {
                this._hasRecom = true;
                this._recomData = _loc_1;
            }
            return;
        }// end function

        public function get isStore() : Boolean
        {
            return this._isStore;
        }// end function

        public function get storeFreePages() : int
        {
            return this._storeFreePages;
        }// end function

        public function get storePrice() : Number
        {
            return this._storePrice;
        }// end function

        public function get storeDiscount() : Number
        {
            return this._storeDiscount;
        }// end function

        public function get storeCookie() : String
        {
            return this._storeCookie;
        }// end function

        public function get storeCallBack() : String
        {
            return this._storeCallBack;
        }// end function

        public function get recomData() : Array
        {
            return this._recomData;
        }// end function

        public function get isFree() : Boolean
        {
            return this._isFree;
        }// end function

        public function get hasRecom() : Boolean
        {
            return this._hasRecom;
        }// end function

    }
}
